package com.javasm.crm.controller.repository;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.javasm.crm.common.http.AxiosResult;
import com.javasm.crm.domin.criteria.repositrory.OutRepoCriteria;
import com.javasm.crm.domin.entity.repository.Outrepo;
import com.javasm.crm.domin.entity.repository.Outrepogoods;
import com.javasm.crm.domin.vo.repository.OutrepoVO;
import com.javasm.crm.domin.vo.repository.OutrepogoodsVO;
import com.javasm.crm.service.repository.IOutrepoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lirui
 * @since 2021-07-16
 */
@RestController
@RequestMapping("/crm/outrepo")
public class OutrepoController {

    @Resource
    private IOutrepoService outrepoService;

    @GetMapping("generateOutRepo")
    @ApiOperation(value = "出库订单id", notes = "条件、分页均可")
    public AxiosResult generateOutRepo(Integer id, HttpServletRequest request){

//        Object loginUser = request.getSession().getAttribute("loginUser");

        String userName = "Loong";

        System.out.println(id);

        boolean flag = outrepoService.generateOutRepo(id,userName);

        String message = flag ? "生成成功！" : "生成失败！";

        return flag ? AxiosResult.success(message) : AxiosResult.error(message, null);
    }

    @GetMapping("getOutRepo")
    public AxiosResult getOutRepo(OutRepoCriteria outRepoCriteria){

        Page<Outrepo> page = outrepoService.getOutRepo(outRepoCriteria);

        return AxiosResult.success(page);
    }

    @GetMapping("getGoods")
    public AxiosResult getGoods(Integer id){

        List<OutrepogoodsVO> list = outrepoService.getGoods(id);

        return AxiosResult.success(list);
    }

    @PostMapping("enterOutRepoGoods")
    public AxiosResult enterOutRepoGoods(@RequestBody OutrepoVO outrepoVO){

        boolean flag = outrepoService.enter(outrepoVO);

        String message = flag ? "录入成功！" : "录入失败！";

        return flag ? AxiosResult.success(message) : AxiosResult.error(message, null);
    }

    @PostMapping("approveOutRepo")
    public AxiosResult approveOutRepo(@RequestBody Outrepo outrepo, HttpServletRequest request){

//        Object loginUser = request.getSession().getAttribute("loginUser");

        String userName = "Bai";

        boolean flag = outrepoService.approve(outrepo, userName);

        String message = flag ? "审核成功！" : "审核失败！";

        return flag ? AxiosResult.success(message) : AxiosResult.error(message, null);
    }

    @GetMapping("repoOut")
    public AxiosResult repoOut(Integer id){

        boolean flag = outrepoService.repoOut(id);

        String message = flag ? "审核成功！" : "审核失败！";

        return flag ? AxiosResult.success(message) : AxiosResult.error(message, null);
    }
}
